class LoginController < ApplicationController
 def index
  end

  def login
   
      @user = User.find_by_user_name_and_password(params[:user_name], params[:password])
      
      if @user.nil?
        redirect_to (url_for(:controller => 'login', :action => 'usernotfound', :message => 'Invalid'))
        
      else
        session[:logged_in]=1
        session[:user_id]= @user.id
        session[:user_name] = @user.user_name
        session[:is_admin] = @user.admin
        redirect_to (url_for(:controller=>'recipe',:action=>'index'))
        
      end
    
  end

  def notfound
      flash[:notice] = "Username and/or password not found. Please re-enter username and password. Do not leave form blank"
      redirect_to :action => 'index'
      
  end
 

  def logout
    session[:logged_in]= 0
    session[:user_id] = 0
    session[:user_name] = 0
    session[:is_admin] = false
    redirect_to (url_for(:controller=>'recipe',:action=>'index'))
  end


end
